4. Linux File,Directory Permissions

Since Linux is a multiuser OS it provides file authorization as a security feature to prevent people from accessing each other’s confidential files.

Linux divides authorization into 2 levels:

  1. Ownership

  2. Permission

Command to view file permissions:

ls -l

f774296848561075fa2802d17d830559.png

a532ef7d5b2fd42ca9bb7cba7cf0a44e.png

There are 3 permissions of each file one each for user,group and other.


6bde03f50fb1d5ec3ed6959a866f20a1.png

fba9358608815e3a0c1d7f9043400270.png


Permissions

993aedc47d6b48bd071a93e0345e2aa7.png

“rwx” characters shows operations each owner can perform on file


Ownership

Note: Whenever a user is created, by default, they are added to a new group with the same name as the username. This is called the primary group of the user.
Ex: user – john, group - john


Reading the security permissions

0a91c1a5b4631b439653afb2c495b5e3.png

Ex: rw-r-xr--


Changing file/directory permissions with 'chmod' command

Using the command, we can set permissions (read, write, execute) on a file/directory for the owner(user), group and the world(others).

Syntax:

chmod [permissions] [filename]

List permissions of a file/directory

ls -l [file,directory name]

  1. Absolute (Numeric) mode
    In this mode, file permissions are not represented as characters but a three-digit octal number.
    In this mode, you change permissions for all 3 owners.

4eed9b6a5b0e68225385d4a11df1618d.png

For Ex: '764' absolute code says the following: rwxrw-r--

80cf1ee4d7a3afbf52152a76a7039afa.png

bd8a84f7db508dba9beef6b986c79013.png

  1. Symbolic mode
    In this mode, you can modify permissions of a specific owner using mathematical symbols.

8276b52d97fb94e4c3d71fe661b5474c.png

39ef47b438ab42c62774f2e088e40f90.png

fcae174c714ddf30cd8e91f29db999a6.png